import os.path
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
# 导入select类
from selenium.webdriver.support.select import Select
file = "file:///" + os.path.abspath("html2") + '/注册实例.html'
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(file)
time.sleep(2)

# 创建select对象
s1 = driver.find_element(By.ID, "select")
select = Select(s1)
# 通过下标获取
time.sleep(2)
select.select_by_index(1)
time.sleep(1)
# 通过value值获取
select.select_by_value('gz')
time.sleep(2)
# 通过文本内容获取
time.sleep(1)
select.select_by_visible_text("上海")
time.sleep(1)
driver.quit()
